package com.ghost.utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.geom.Point;
	import flash.utils.setTimeout;
	
	public class MovieClipUtil
	{
				
		public static function removeMovieClipChild(parenClip:DisplayObjectContainer , child:DisplayObject):Boolean
		{
			if(child!=null&&parenClip!=null&&parenClip.contains(child))
			{
				parenClip.removeChild(child);
				return true;
			}
			return false;
		}
		
		public static function removeAllChild(child:DisplayObjectContainer):void
		{
			if(child == null) return ;
			while(child.numChildren>0)
			{
				child.removeChildAt(0);	
			}
			GC.nowGC();
		}
		
		public static function swapChildToTop(parenClip:DisplayObjectContainer , child:DisplayObject):void
		{
			if( parenClip.contains(child) )  parenClip.setChildIndex(child,parenClip.numChildren-1);	
		}
		
		/**
		 * currentShowWin: 要调整位置的窗口
		 * mc : 窗口的依据
		 * par : 大容器
		 */ 
		public static function checkXYInCenter(currentShowWin:DisplayObjectContainer , mc:DisplayObjectContainer , par:DisplayObjectContainer):void
		{
			var p2:Point = new Point(mc.x,mc.y);
			
			if(p2.x<par.width/2)
			{
				if(p2.y<par.height/2)
				{
					//左上角
					currentShowWin.x = p2.x+mc.width/2 ;
					currentShowWin.y = p2.y+mc.height/2 ;
				}
				else
				{
					//左下角
					currentShowWin.x = p2.x+mc.width/2 ;
					currentShowWin.y = p2.y+mc.height/2-currentShowWin.height ;
				}
			}
			else
			{
				if(p2.y<par.height/2)
				{
					//右上角
					currentShowWin.x = p2.x+mc.width/2-currentShowWin.width ;
					currentShowWin.y = p2.y+mc.height/2 ;	
				}
				else
				{
					//右下角
					currentShowWin.x = p2.x+mc.width/2-currentShowWin.width ;
					currentShowWin.y = p2.y-mc.height/2 ;
				}
			}
		}
		
		
	}
}